package com.hs.jpademo1.service.impl;

import com.hs.jpademo1.dao.UserDao;
import com.hs.jpademo1.entity.User;
import com.hs.jpademo1.service.UserService;
import com.hs.jpademo1.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao mapper;

    @Override
    public User login(User user) throws RuntimeException {
        User login = mapper.findByUsername(user.getUsername());
        if (login == null) {
            throw new RuntimeException("用户名错误");
        }
        if(!login.getPassword().equals(MD5Util.encode(user.getPassword()))){
            throw new RuntimeException("密码错误");
        }
        return login;
    }
}
